package com.vueapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vueapi.annotation.OperationLog;
import com.vueapi.domain.HjComment;
import com.vueapi.domain.HjOperationLog;
import com.vueapi.service.HjOperationLogService;
import com.vueapi.mapper.HjOperationLogMapper;
import com.vueapi.utils.ParseUtils;
import com.vueapi.utils.ResultUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
* @author 15442
* @description 针对表【hj_operation_log】的数据库操作Service实现
* @createDate 2022-09-20 14:36:03
*/
@Service
public class HjOperationLogServiceImpl extends ServiceImpl<HjOperationLogMapper, HjOperationLog>
    implements HjOperationLogService{

    @Override
    public ResultUtils listPage(Integer pageNum, Integer pageSize, String operationName, String ip, String spendTime) {
        LambdaQueryWrapper<HjOperationLog> cw = new LambdaQueryWrapper<>();
        cw.like(!operationName.equals(""),HjOperationLog::getOperationName,operationName);
        cw.eq(!ip.equals(""),HjOperationLog::getIp,ip);
        // 查询接口耗时大于xx
        if(!spendTime.equals("")){
            int time = Integer.parseInt(spendTime);
            cw.gt(HjOperationLog::getSpendTime,time);
        }
        cw.orderByDesc(HjOperationLog::getCreateTime);

        Page<HjOperationLog> operationLogPage = this.page(new Page<>(pageNum, pageSize), cw);

        return ResultUtils.success(operationLogPage);
    }

    @Override
    public Boolean operationDeleteByIds(String ids) {
        List<Integer> operationIds = ParseUtils.intArrayToList(ParseUtils.stringToIntArray(ids));
        return removeByIds(operationIds);
    }
}




